/**
 *
 */
package cn.edu.cqupt.cyExam.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import cn.edu.cqupt.cyExam.myBatis.bean.Graduateq;
import cn.edu.cqupt.cyExam.myBatis.bean.User;
import cn.edu.cqupt.cyExam.utils.JSONResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import cn.edu.cqupt.cyExam.service.QuestionService;

import java.util.List;

/**
 * @author asus
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/Question")
public class QuestionController {

	@Resource
	private QuestionService  questionService;

	@RequestMapping("/QueryQuestion")
	public JSONResult queryGraduateq(
			@RequestParam(value="type_name",required=false) String type_name,
			@RequestParam(value="kind",required=false) String kind,
			HttpSession session,
			HttpServletRequest request
	) {
		if(type_name != null){
			if(kind != null){
				List<Graduateq> graduateqs = questionService.queryGraduateq(type_name, kind);
				return new JSONResult(0,"题目查询成功",1,graduateqs);
			}else {
				return new JSONResult(0,"题目type_name为空",0,null);
			}
		}else {
			return new JSONResult(0,"题目kind为空",0,null);
		}






	}

	@RequestMapping("/DeleteQuestion")
	public JSONResult deleteGraduateq(@RequestParam(value="graduate_id",required=false) Integer graduate_id,
								 HttpSession session,
								 HttpServletRequest request) {
		System.out.print(graduate_id);
		System.out.print("_____lining_____");
		Graduateq graduateq=questionService.getGraduateqByid(graduate_id);
		if(graduateq != null){
			int deleteUser = questionService.deleteGraduateq(graduateq.getGraduateqName());
			System.out.print("------------------------");
			System.out.print(deleteUser);
			return new JSONResult(0,"删除成功",1,null);

		}
		return new JSONResult(1,"该应届生题目不存在",1,null);
	}
	@RequestMapping("/UnclearQuestion")//模糊查询
	public JSONResult unclearGraduateq(@RequestParam(value = "graduate_name", required = false) String graduate_name,
									   HttpSession session,
									   HttpServletRequest request ) {
		String graduatequestion = null;
		List<Graduateq> graduateqs = questionService.getGraduateqByname(graduate_name);
		for (Graduateq  graduateq : graduateqs) {

			graduatequestion = graduateq.toString();
			System.out.println(graduatequestion);
		}

		return new JSONResult(1, "模糊查询应届生试题成功", 1, graduateqs);

	}

}
